<?php
/**
 * Defines Kodform_Element_Submit class
 *
 *
 * @copyright 	Copyright (c) 2006 Boris Tomic (kodmasin.net)
 * @category 	Kodform
 * @package 	Kodform
 * @author 		Boris Tomic
 * @license 	http://boris.kodmasin.net/kodform4:license The BSD License
 *
 */

require_once 'Kodform/Element.php';
require_once 'Kodform/Attributes.php';

class Kodform_Element_Submit extends Kodform_Element{
	function __construct($id, $label){
		parent::__construct($id);
		$this->displayName = $label;
	}
	/**
	 * submit is always valid so here is overloaded Kod_Form_Element method
	 * 
	 * @return boolean always true
	 */
	function validate(){
		return true;
	}
	/**
	 * default display (rendering)
	 */
	function display(Kodform_Attributes $attributes = null){
		if($attributes === null)
			$attributes = new Kodform_Attributes();
		?>
<input id="<?php print $this->id?>" name="<?php print $this->id?>" type="submit"<?php print $attributes->normal->display();?> value="<?php print $this->displayName;?>" />
<?php
	}
	/**
	 * check if this button was clicked (submited)
	 * 
	 * ususally used by parent form
	 */
	function isSubmited(){
		$method = $this->form->getMethod();
		if($method == 0)
			if(isset($_POST[$this->id]))
				return true;
		if($method == 1)
			if(isset($_GET[$this->id]))
				return true;
		return false;
	}
	/**
	 * reset form submit data
	 * 
	 * basicli this function deletes $_POST['submitname'] variable
	 *
	 */
	function clear(){
		$method = $this->form->getMethod();
		if($method == 0)
			if(array_key_exists($this->id, $_POST))
				unset($_POST[$this->id]);
		if($method == 1)
			if(array_key_exists($this->id, $_GET))
				unset($_GET[$this->id]);
	}
}
